<?php


namespace app\open\service;


use app\common\controller\Api;
use think\Config;
use think\Db;
use app\common\model\Order as OrderModel;
use app\common\model\OrderProof;
use app\common\model\OrderLog;
use app\common\model\UserRoll;
use app\common\model\OrderFail;
use fast\Http;

class OcrService extends BaseService
{
    /**
     * 图片信息识别
     * @DateTime 2023-05-15T22:08:55+0800
     * @param    [type]                   $shop_type [description]
     * @param    array                    $proof     [description]
     * @return   [type]                              [description]
     */
    public function ocr1($play, $order, $proof, $data = [],$contents = '')
    {
        $shop_type = $play['shop_type'];
        // one_image识别订单状态和订单号和下单时间
        // two_image识别店铺名和实付金额
        // three_image识别评分和图片
        $ims = ['one_image','two_image','three_image'];
        $defarr = ['订单状态','订单号','下单时间','店铺名称','实付金额','反馈识别'];
        $resarr = [];
        $elm_check=0;
        // cps_id大于0时不需要验证，表示已经验证了'订单状态','订单号','下单时间','店铺名称','实付金额'
        if ($order['cps_id']>0 && $order['wm_completed']==1) { 
            $resarr['订单状态'] = 1;
            $resarr['店铺名称'] = 1;
            $resarr['订单号'] = 1;
            $resarr['下单时间'] = 1;
            $resarr['实付金额'] = 1;
        } else {
            // 饿了么接口查询订单状态
            // if ($shop_type==2) {
            //     // 当图片上的订单号和用户提交的订单号不一样时，不使用接口
            //     if ($contents) {
            //         $contents = str_replace(' ', '', $contents);
            //         if (strpos($contents,$proof['wm_order_sn'])!==false) {
            //             $ElemService = new \services\ElemService('');
            //             $res = $ElemService->check($proof['wm_order_sn']);
            //             $decode = json_decode($res,1);
            //         }
            //     } else {
            //         $ElemService = new \services\ElemService('');
            //         $res = $ElemService->check($proof['wm_order_sn']);
            //         $decode = json_decode($res,1);
            //     }
            //     if (isset($decode['alibaba_alsc_union_eleme_tool_order_attrbute_check_response']['biz_error_code']) && $decode['alibaba_alsc_union_eleme_tool_order_attrbute_check_response']['biz_error_code']==0) {
            //         $elm_check = 1;
            //         $resarr['订单号'] = 1;
            //         $wm_order_sn = $proof['wm_order_sn'];
            //         // 是否是今天下单
            //         if (isset($decode['alibaba_alsc_union_eleme_tool_order_attrbute_check_response']['data']['order_info']['create_time'])) {
            //             $times = strtotime($decode['alibaba_alsc_union_eleme_tool_order_attrbute_check_response']['data']['order_info']['create_time']);
            //             $timestap = $times-strtotime(date('Y-m-d',$order['place_time']).' 00:00:00');
            //             if ($timestap<86400 && $timestap>0) {
            //                 $resarr['下单时间'] = 1;
            //             }
            //         }
            //         // 是否完成订单
            //         if (isset($decode['alibaba_alsc_union_eleme_tool_order_attrbute_check_response']['data']['order_info']['finish_time'])) {
            //             $timestap = strtotime($decode['alibaba_alsc_union_eleme_tool_order_attrbute_check_response']['data']['order_info']['finish_time']);
            //             if ($timestap) {
            //                 $resarr['订单状态'] = 1;
            //             }
            //         }
            //         // 店铺名称
            //         if (isset($decode['alibaba_alsc_union_eleme_tool_order_attrbute_check_response']['data']['order_info']['shop_name'])) {
            //             $shop_name = $decode['alibaba_alsc_union_eleme_tool_order_attrbute_check_response']['data']['order_info']['shop_name'];
            //             $img_shop_name = $shop_name;
            //             $shop_name =  str_replace('（', '', $shop_name);
            //             $shop_name =  str_replace('(', '', $shop_name);
            //             $shop_name =  str_replace('）', '', $shop_name);
            //             $shop_name =  str_replace(')', '', $shop_name);
            //             $shop_name =  str_replace(' ', '', $shop_name);
            //             $shop_name =  str_replace('！', '', $shop_name);
            //             $shop_name =  str_replace('!', '', $shop_name);
            //             // $shop_name =  str_replace('.', '', $shop_name);
            //             $shop_name =  str_replace('·', '.', $shop_name);
            //             $shop_name =  str_replace('・', '.', $shop_name);
            //             $shop_name =  str_replace('•', '.', $shop_name);
            //             $shop_name =  str_replace('●', '.', $shop_name);
            //             $shop_name =  str_replace('.', '', $shop_name);

            //             $shop_name2 =  str_replace('（', '', $play['shop_name']);
            //             $shop_name2 =  str_replace('(', '', $shop_name2);
            //             $shop_name2 =  str_replace('）', '', $shop_name2);
            //             $shop_name2 =  str_replace(')', '', $shop_name2);
            //             $shop_name2 =  str_replace(' ', '', $shop_name2);
            //             $shop_name2 =  str_replace('！', '', $shop_name2);
            //             $shop_name2 =  str_replace('!', '', $shop_name2);
            //             // $shop_name2 =  str_replace('.', '', $shop_name2);
            //             $shop_name2 =  str_replace('·', '.', $shop_name2);
            //             $shop_name2 =  str_replace('・', '.', $shop_name2);
            //             $shop_name2 =  str_replace('•', '.', $shop_name2);
            //             $shop_name2 =  str_replace('●', '.', $shop_name2);
            //             $shop_name2 =  str_replace('.', '', $shop_name2);
            //             if ($shop_name==$shop_name2) {
            //                 $resarr['店铺名称'] = 1;
            //             }
            //         }
            //     } elseif (isset($decode['error_response']['sub_msg']) && $decode['error_response']['sub_msg']=='无效订单号') {
            //         $elm_check = 2;// 订单状态，店铺名称，订单号，下单时间都判断为不合格
            //         foreach ($defarr as $k => $v) {
            //             if (!isset($resarr[$v])) {
            //                 $resarr[$v] = 0;
            //                 $res = 0;
            //             }
            //         }
            //         return ['res'=>0,'resarr'=>$resarr,'money'=>isset($money)?$money:0,'img_shop_name'=>isset($img_shop_name)?$img_shop_name:'','wm_order_sn'=>isset($wm_order_sn)?$wm_order_sn:'','place_time'=>isset($times)?date('Y-m-d H:i:s',$times):''];
            //     } else {
            //         \think\Log::write($proof['wm_order_sn'].'接口查询失败');
            //         // foreach ($defarr as $k => $v) {
            //         //     if (!isset($resarr[$v])) {
            //         //         $resarr[$v] = 0;
            //         //         $res = 0;
            //         //     }
            //         // }
            //         // return ['res'=>0,'resarr'=>$resarr,'money'=>isset($money)?$money:$proof['actual_pay']];
            //     }
            // }
        }
        if ($play['scheme_no']==3) { // 无需反馈评价
            $resarr['反馈识别'] = 1;
        }
        if ($play['play_type']!=1) { // 返利餐
            $resarr['实付金额'] = 1;
        }

        $res = 1;
        $logtext = '';
        // 判断是否app截图验证过，验证过的话同步验证结果
        $play_order_proof = Db::name('play_order_proof')->where('id',$proof['id'])->field('machine_audit_desc,machine_audit_state,actual_pay')->find();
        $machine_audit_desc = $play_order_proof['machine_audit_desc'];
        $machine_audit_desc = json_decode($machine_audit_desc,1);
        if ($play_order_proof['machine_audit_state']!=0 && $machine_audit_desc && is_array($machine_audit_desc)) {
            foreach ($defarr as $k => $v) {
                if (isset($machine_audit_desc[$v]) && $machine_audit_desc[$v]==1) {
                    $resarr[$v] = 1;
                }
            }
        }
        if ($play['shop_type']==3) {
            foreach ($defarr as $k => $v) {
                if (isset($machine_audit_desc[$v]) && $machine_audit_desc[$v]==1) {
                    $resarr[$v] = 1;
                }
            }
        }
        // 如果是前端传文字内容，不需要ocr识别的情况
        if ($contents && !$data) {
            $data['one_image'] = $contents;
        }
        if ($shop_type==1) {//美团
            foreach ($ims as $key => $value) {
                if (isset($data[$value]) && $data[$value]) {
                    // 如果是前端传文字内容，不需要ocr识别的情况
                    if (!$contents || $value=='three_image') {
                        if (strpos($data[$value],'://')===false) {
                            $file = config('upload_domain').$data[$value]; // 指定图片文件的本地路径或远程url
                        } else {
                            $file = $data[$value]; // 指定图片文件的本地路径或远程url
                        }
                        $ocr = new \services\BaiduocrService(); // 创建对象
                        $result = $ocr->ocr($file); // 调用对象开放的函数
                        if (!isset($result['content'])) { // 识别成功
                            return false;
                        }
                        $ocrdata = $result; // 取得数据
                        if (!$ocrdata['content']) return false;
                        if ($ocrdata['content']=='您的网络好像不太给力，请稍后再试重新加载') {
                            return false;
                        }
                        $pos = strpos($ocrdata['content'],'客服电话');
                        if ($pos!==false && $pos<5) {
                            return false;
                        }
                        if (strpos($ocrdata['content'],'发送验证码')>1) {
                            return false;
                        }
                        // $pos = strpos($ocrdata['content'],'努力加载中');
                        // if ($pos!==false) {
                        //     return false;
                        // }
                        $content = str_replace(' ', '', $ocrdata['content']);
                    } else {
                        $content = $contents;
                    }
                    $content = str_replace('（', '', $content);
                    $content = str_replace('(', '', $content);
                    $content = str_replace('）', '', $content);
                    $content = str_replace(')', '', $content);
                    $content = str_replace('：', ':', $content);
                    $content = str_replace('！', '', $content);
                    $content = str_replace('!', '', $content);
                    $content =  str_replace(' ', '', $content);
                    $content =  str_replace('·', '.', $content);
                    $content =  str_replace('•', '.', $content);
                    $content =  str_replace('●', '.', $content);
                    $content =  str_replace('¥', '￥', $content);
                    $content = match_dot($content);
                    if (strpos($content, '.')) {
                        $content = match_dot($content);
                    }
                    \think\Log::write($proof['wm_order_sn'].'ocr识别文字：',$content);
                    if (isset($content) && $content) {
                        // 识别订单状态
                        if (!isset($resarr['订单状态']) && (strpos($content, '订单已完成')!==false || strpos($content, '订单已存入智能柜')!==false || strpos($content, '餐品已取出')!==false || strpos($content, '商品已送达')!==false || strpos($content, '订单已送达')!==false)) {
                            $resarr['订单状态'] = 1;
                        }
                        if (!isset($resarr['订单状态']) && strpos($content, '已提前')!==false && strpos($content, '分钟送达')!==false) {
                            $resarr['订单状态'] = 1;
                        }
                        // 识别店铺名称
                        $shop_name =  str_replace('（', '', $play['shop_name']);
                        $shop_name =  str_replace('(', '', $shop_name);
                        $shop_name =  str_replace('）', '', $shop_name);
                        $shop_name =  str_replace(')', '', $shop_name);
                        $shop_name =  str_replace(' ', '', $shop_name);
                        $shop_name =  str_replace('！', '', $shop_name);
                        $shop_name =  str_replace('!', '', $shop_name);
                        // $shop_name =  str_replace('.', '', $shop_name);
                        $shop_name =  str_replace('·', '.', $shop_name);
                        $shop_name =  str_replace('・', '.', $shop_name);
                        $shop_name =  str_replace('•', '.', $shop_name);
                        $shop_name =  str_replace('●', '.', $shop_name);
                        $shop_name =  str_replace('.', '', $shop_name);
                        // $shop_name = mb_substr($shop_name, 0,16);
                        $logtext .= '店铺名称：'.$shop_name;
                        // 店铺名称中包含英文匹配15个，不包含英文匹配15个
                        if (preg_match('/[A-Za-z]/', $shop_name)) {
                            $shop_name2 = mb_substr($shop_name, 0,15);
                            if (!isset($resarr['店铺名称']) && strpos($content, $shop_name2)!==false) {
                                $resarr['店铺名称'] = 1;
                                $img_shop_name = $shop_name2;
                            }
                        } else {
                            if (mb_strlen($shop_name)>16) {
                                $shop_name2 = mb_substr($shop_name, 0,14);
                                if (!isset($resarr['店铺名称']) && strpos($content, $shop_name2)!==false) {
                                    $resarr['店铺名称'] = 1;
                                    $img_shop_name = $shop_name2;
                                }
                            } else {
                                $shop_name2 = mb_substr($shop_name, 0,12);
                                if (!isset($resarr['店铺名称']) && strpos($content, $shop_name2)!==false) {
                                    $resarr['店铺名称'] = 1;
                                    $img_shop_name = $shop_name2;
                                }
                            }
                        }
                        // 识别订单号
                        if (!isset($resarr['订单号'])) {
                            $noarr = explode('订单号码', $content);
                            // 订单号的位数
                            $amount = strlen($proof['wm_order_sn']);
                            if (isset($noarr[1]) && $noarr[1]) {
                                $noarr[1] = substr($noarr[1],0,$amount);// 订单号位数
                                $logtext .= '，订单号码：'.$noarr[1];
                                if ($noarr[1]==$proof['wm_order_sn']) {
                                    $resarr['订单号'] = 1;
                                }
                                $wm_order_sn = $noarr[1];
                            }
                            // 识别订单号
                            if (!isset($resarr['订单号'])) {
                                $noarr = explode('订单编号', $content);
                                if (isset($noarr[1]) && $noarr[1]) {
                                    $noarr[1] = substr($noarr[1],0,$amount);// 订单号位数
                                    $logtext .= '，订单编号：'.$noarr[1];
                                    if ($noarr[1]==$proof['wm_order_sn']) {
                                        $resarr['订单号'] = 1;
                                    }
                                    $wm_order_sn = $noarr[1];
                                }
                            }
                        }
                        // 识别下单时间：是否是今天下单
                        if (!isset($resarr['下单时间'])) { 
                            $noarr = explode('下单时间', $content);
                            if (isset($noarr[1]) && $noarr[1]) {
                                $days = substr($noarr[1],0,10);// 日期
                                $time = substr($noarr[1],10,8);// 时间
                                $logtext .= '，下单时间：'.$days.$time;
                                $times = strtotime($days.' '.$time);
                                // if ($time && $time<time() && $time>$order['place_time']) {
                                //     $resarr['下单时间'] = 1;
                                // }
                                // 校对下单时间,所处为同一个小时或小时以后提交的订单通过
                                // $time = strtotime(date('Y-m-d H',$time).':00:00');
                                $place_time = strtotime(date('Y-m-d',$order['place_time']).' 00:00:00');
                                if (time()>=$times && $times>=$place_time) {
                                    $resarr['下单时间'] = 1;
                                }
                            }
                            if (!isset($resarr['下单时间'])) { 
                                $noarr = explode('订单时间', $content);
                                if (isset($noarr[1]) && $noarr[1]) {
                                    $days = substr($noarr[1],0,10);// 日期
                                    $time = substr($noarr[1],10,8);// 时间
                                    $logtext .= '，下单时间：'.$days.$time;
                                    $times = strtotime($days.' '.$time);
                                    // if ($time && $time<time() && $time>$order['place_time']) {
                                    //     $resarr['下单时间'] = 1;
                                    // }
                                    // 校对下单时间,所处为同一个小时或小时以后提交的订单通过
                                    // $time = strtotime(date('Y-m-d H',$time).':00:00');
                                    $place_time = strtotime(date('Y-m-d',$order['place_time']).' 00:00:00');
                                    if (time()>=$times && $times>=$place_time) {
                                        $resarr['下单时间'] = 1;
                                    }
                                }
                            }
                        }
                        // 识别评价：是否有两个5星
                        if ($key==2 && !isset($resarr['反馈识别'])) {
                            if (strpos($content,'5星') && !strpos($content,'4星') && !strpos($content,'3星') && !strpos($content,'2星') && !strpos($content,'1星')) {
                                $date = date('Y-m-d',$order['place_time']);
                                $date2 = date('Y.m.d',$order['place_time']);
                                $date3 = date('Y-m-d',($order['place_time']+86400));
                                $date4 = date('Y.m.d',($order['place_time']+86400));
                                $noarr = explode('5星', $content);
                                $logtext .= '，反馈识别：'.count($noarr);
                                if (count($noarr)>=3) {
                                    // 反馈识别还需要确定店铺名称和日期
                                    $shop_name = mb_substr($shop_name, 0,6);
                                    if (strpos($content,$shop_name)!==false && (strpos($content,$date) || strpos($content,$date2) || strpos($content,$date3) || strpos($content,$date4) || strpos($content,'今天') || strpos($content,'刚刚') || strpos($content,'分钟前') || strpos($content,'小时前'))) {
                                    // if (strpos($content,$shop_name) && (strpos($content,'刚刚') || strpos($content,'分钟前') || strpos($content,'小时前'))) {
                                        $resarr['反馈识别']=1;
                                    }
                                }
                                // 识别评价：是否有两个5星
                                if (!isset($resarr['反馈识别'])) {
                                    $noarr = explode('非常满意', $content);
                                    $logtext .= '，反馈识别非常满意：'.count($noarr);
                                    if (count($noarr)>=2) {
                                        // 反馈识别还需要确定店铺名称和日期
                                        $shop_name = mb_substr($shop_name, 0,6);
                                        $date = date('Y-m-d',$order['place_time']);
                                        $date2 = date('Y.m.d',$order['place_time']);
                                        if (strpos($content,$shop_name)!==false && (strpos($content,$date) || strpos($content,$date2) || strpos($content,$date3) || strpos($content,$date4) || strpos($content,'今天') || strpos($content,'刚刚') || strpos($content,'分钟前') || strpos($content,'小时前'))) {
                                        // if (strpos($content,$shop_name) && (strpos($content,'刚刚') || strpos($content,'分钟前') || strpos($content,'小时前'))) {
                                            $resarr['反馈识别']=1;
                                        }
                                    }
                                }
                            }
                        }
                        // 识别实付金额：是否有两个5星
                        if ($key!=2 && !isset($resarr['实付金额'])) {
                            $noarr = explode('合计￥', $content);
                            if (isset($noarr[1]) && $noarr[1]) {
                                preg_match_all('/[0-9]+(?:\.[0-9]+)?/', $noarr[1], $matches);
                                $money = isset($matches[0][0])?$matches[0][0]:0;
                                $logtext .= '，实付金额1：'.$money;
                                if (floatval($money) && floatval($money)>=$play['user_pay']) {
                                    $resarr['实付金额']=1;
                                }
                            }
                            if (!isset($resarr['实付金额'])) {
                                $noarr = explode('共计￥', $content);
                                if (isset($noarr[1]) && $noarr[1]) {
                                    preg_match_all('/[0-9]+(?:\.[0-9]+)?/', $noarr[1], $matches);
                                    $money = isset($matches[0][0])?$matches[0][0]:0;
                                    $logtext .= '，实付金额2：'.$money;
                                    if (floatval($money) && floatval($money)>=$play['user_pay']) {
                                        $resarr['实付金额']=1;
                                    }
                                }
                            }
                            if (!isset($resarr['实付金额'])) {
                                $noarr = explode('实付￥', $content);
                                if (count($noarr)>1) $noarr[1] = end($noarr);
                                if (isset($noarr[1]) && $noarr[1]) {
                                    preg_match_all('/[0-9]+(?:\.[0-9]+)?/', $noarr[1], $matches);
                                    $money = isset($matches[0][0])?$matches[0][0]:0;
                                    $logtext .= '，实付金额3：'.$money;
                                    if (floatval($money) && floatval($money)>=$play['user_pay']) {
                                        $resarr['实付金额']=1;
                                    }
                                }
                            }
                            if (!isset($resarr['实付金额'])) {
                                $noarr = explode('实付款￥', $content);
                                if (isset($noarr[1]) && $noarr[1]) {
                                    preg_match_all('/[0-9]+(?:\.[0-9]+)?/', $noarr[1], $matches);
                                    $money = isset($matches[0][0])?$matches[0][0]:0;
                                    $logtext .= '，实付金额4：'.$money;
                                    if (floatval($money) && floatval($money)>=$play['user_pay']) {
                                        $resarr['实付金额']=1;
                                    }
                                }
                            }
                            if (!isset($resarr['实付金额'])) {
                                $noarr = explode('优惠后￥', $content);
                                if (isset($noarr[1]) && $noarr[1]) {
                                    preg_match_all('/[0-9]+(?:\.[0-9]+)?/', $noarr[1], $matches);
                                    $money = isset($matches[0][0])?$matches[0][0]:0;
                                    $logtext .= '，实付金额5：'.$money;
                                    if (floatval($money) && floatval($money)>=$play['user_pay']) {
                                        $resarr['实付金额']=1;
                                    }
                                }
                            }
                            if (!isset($resarr['实付金额'])) {
                                $noarr = explode('元￥', $content);
                                if (isset($noarr[1]) && $noarr[1]) {
                                    preg_match_all('/[0-9]+(?:\.[0-9]+)?/', $noarr[1], $matches);
                                    $endmatch = end($matches);
                                    $money = isset($endmatch[0])?$endmatch[0]:0;
                                    $logtext .= '，实付金额6：'.$money;
                                    if (floatval($money) && floatval($money)>=$play['user_pay']) {
                                        $resarr['实付金额']=1;
                                    }
                                }
                            }
                            if (!isset($resarr['实付金额'])) {
                                $noarr = explode('件￥', $content);
                                if (isset($noarr[1]) && $noarr[1]) {
                                    preg_match_all('/[0-9]+(?:\.[0-9]+)?/', $noarr[1], $matches);
                                    $endmatch = end($matches);
                                    $money = isset($endmatch[0])?$endmatch[0]:0;
                                    $logtext .= '，实付金额7：'.$money;
                                    if (floatval($money) && floatval($money)>=$play['user_pay']) {
                                        $resarr['实付金额']=1;
                                    }
                                }
                            }
                        }
                        // 是否存在”立即配送“文案
                        if (strpos($content, "立即配送")) {
                            $resarr['立即配送']=1;
                        }
                    }
                }
            }
        } elseif ($shop_type==2) {// 饿了么
            foreach ($ims as $key => $value) {
                if (isset($data[$value]) && $data[$value]) {
                    // 如果是前端传文字内容，不需要ocr识别的情况
                    if (!$contents || $value=='three_image') {
                        if (strpos($data[$value],'://')===false) {
                            $file = config('upload_domain').$data[$value]; // 指定图片文件的本地路径或远程url
                        } else {
                            $file = $data[$value]; // 指定图片文件的本地路径或远程url
                        }
                        $ocr = new \services\BaiduocrService(); // 创建对象
                        $result = $ocr->ocr($file); // 调用对象开放的函数
                        if (!isset($result['content'])) { // 识别成功
                            return false;
                        }
                        $ocrdata = $result; // 取得数据
                        if (!$ocrdata['content']) return false;
                        if ($ocrdata['content']=='当前订单信息无效重新加载') {
                            return false;
                        }
                        if (strpos($ocrdata['content'],'获取验证码')>1) {
                            return false;
                        }
                        if (strpos($ocrdata['content'],'同意协议并登录')>1) {
                            return false;
                        }
                        if (strpos($ocrdata['content'],'暂无待评价订单')>1) {
                            return false;
                        }
                        $pos = strpos($ocrdata['content'],'手机号登录');
                        if ($pos!==false) {
                            return false;
                        }
                        $pos = strpos($ocrdata['content'],'重新加载');
                        // $pos = strpos($ocrdata['content'],'不支持零售单重新加载');
                        if ($pos!==false) {
                            return false;
                        }
                        $pos = strpos($ocrdata['content'],'身份验证');
                        if ($pos!==false) {
                            return false;
                        }
                        $content = str_replace(' ', '', $ocrdata['content']);
                    } else {
                        $content = $contents;
                    }

                    $content = str_replace('（', '', $content);
                    $content = str_replace('(', '', $content);
                    $content = str_replace('）', '', $content);
                    $content = str_replace(')', '', $content);
                    $content = str_replace('：', ':', $content);
                    $content = str_replace('！', '', $content);
                    $content = str_replace('!', '', $content);
                    $content =  str_replace(' ', '', $content);
                    $content =  str_replace('·', '.', $content);
                    $content =  str_replace('•', '.', $content);
                    $content =  str_replace('●', '.', $content);
                    $content =  str_replace('¥', '￥', $content);
                    $content = match_dot($content);
                    if (strpos($content, '.')) {
                        $content = match_dot($content);
                    }
                    \think\Log::write($proof['wm_order_sn'].'ocr识别文字：',$content);
                    if (isset($content) && $content) {
                        // 识别订单状态
                        if ($elm_check==0 && !isset($resarr['订单状态']) && (strpos($content, '订单已送达')!==false || strpos($content, '订单已存入智能柜')!==false || strpos($content, '餐品已取出')!==false || strpos($content, '商品已送达')!==false || strpos($content, '商品已取出')!==false)) {
                            $resarr['订单状态'] = 1;
                        }
                        // 识别店铺名称
                        $shop_name =  str_replace('（', '', $play['shop_name']);
                        $shop_name =  str_replace('(', '', $shop_name);
                        $shop_name =  str_replace('）', '', $shop_name);
                        $shop_name =  str_replace(')', '', $shop_name);
                        $shop_name =  str_replace(' ', '', $shop_name);
                        $shop_name =  str_replace('！', '', $shop_name);
                        $shop_name =  str_replace('!', '', $shop_name);
                        // $shop_name =  str_replace('.', '', $shop_name);
                        $shop_name =  str_replace('·', '.', $shop_name);
                        $shop_name =  str_replace('・', '.', $shop_name);
                        $shop_name =  str_replace('•', '.', $shop_name);
                        $shop_name =  str_replace('●', '.', $shop_name);
                        $shop_name =  str_replace('.', '', $shop_name);
                        // $shop_name = mb_substr($shop_name, 0,16);
                        $logtext .= '店铺名称：'.$shop_name;
                        // 店铺名称中包含英文匹配15个，不包含英文匹配15个
                        if (preg_match('/[A-Za-z]/', $shop_name)) {
                            $shop_name2 = mb_substr($shop_name, 0,15);
                            if (!isset($resarr['店铺名称']) && strpos($content, $shop_name2)!==false) {
                                $resarr['店铺名称'] = 1;
                                $img_shop_name = $shop_name2;
                            }
                        } else {
                            if (mb_strlen($shop_name)>16) {
                                $shop_name2 = mb_substr($shop_name, 0,14);
                                if (!isset($resarr['店铺名称']) && strpos($content, $shop_name2)!==false) {
                                    $resarr['店铺名称'] = 1;
                                    $img_shop_name = $shop_name2;
                                }
                            } else {
                                $shop_name2 = mb_substr($shop_name, 0,12);
                                if (!isset($resarr['店铺名称']) && strpos($content, $shop_name2)!==false) {
                                    $resarr['店铺名称'] = 1;
                                    $img_shop_name = $shop_name2;
                                }
                            }
                        }
                        // 识别订单号
                        if ($elm_check==0 && !isset($resarr['订单号'])) {
                            $noarr = explode('订单号码', $content);
                            // 订单号的位数
                            $amount = strlen($proof['wm_order_sn']);
                            if (isset($noarr[1]) && $noarr[1]) {
                                $noarr[1] = substr($noarr[1],0,$amount);// 订单号位数
                                $logtext .= '，订单号码：'.$noarr[1];
                                if ($noarr[1]==$proof['wm_order_sn']) {
                                    $resarr['订单号'] = 1;
                                }
                                $wm_order_sn = $noarr[1];
                            }
                            // 识别订单号
                            if (!isset($resarr['订单号'])) {
                                $noarr = explode('订单号', $content);
                                if (isset($noarr[1]) && $noarr[1]) {
                                    $noarr[1] = substr($noarr[1],0,$amount);// 订单号位数
                                    $logtext .= '，订单号：'.$noarr[1];
                                    if ($noarr[1]==$proof['wm_order_sn']) {
                                        $resarr['订单号'] = 1;
                                    }
                                    $wm_order_sn = $noarr[1];
                                }
                            }
                        }
                        // 识别下单时间：是否是今天下单
                        if ($elm_check==0 && !isset($resarr['下单时间'])) { 
                            $noarr = explode('下单时间', $content);
                            if (isset($noarr[1]) && $noarr[1]) {
                                $days = substr($noarr[1],0,10);// 日期
                                $time = substr($noarr[1],10,8);// 时间
                                $logtext .= '，下单时间：'.$days.$time;
                                $times = strtotime($days.' '.$time);
                                // if ($time && $time<time() && $time>$order['place_time']) {
                                //     $resarr['下单时间'] = 1;
                                // }
                                // 校对下单时间,所处为同一个小时或小时以后提交的订单通过
                                // $time = strtotime(date('Y-m-d H',$time).':00:00');
                                $place_time = strtotime(date('Y-m-d',$order['place_time']).' 00:00:00');
                                if (time()>=$times && $times>=$place_time) {
                                    $resarr['下单时间'] = 1;
                                }
                            }
                            if (!isset($resarr['下单时间'])) { 
                                $noarr = explode('订单时间', $content);
                                if (isset($noarr[1]) && $noarr[1]) {
                                    $days = substr($noarr[1],0,10);// 日期
                                    $time = substr($noarr[1],10,8);// 时间
                                    $logtext .= '，下单时间：'.$days.$time;
                                    $times = strtotime($days.' '.$time);
                                    // if ($time && $time<time() && $time>$order['place_time']) {
                                    //     $resarr['订单时间'] = 1;
                                    // }
                                    // 校对下单时间,所处为同一个小时或小时以后提交的订单通过
                                    // $time = strtotime(date('Y-m-d H',$time).':00:00');
                                    $place_time = strtotime(date('Y-m-d',$order['place_time']).' 00:00:00');
                                    if (time()>=$times && $times>=$place_time) {
                                        $resarr['下单时间'] = 1;
                                    }
                                }
                            }
                        }
                        // 识别评价：是否有两个5星
                        if ($key==2 && !isset($resarr['反馈识别'])) {
                            if (strpos($content,'5星') && !strpos($content,'4星') && !strpos($content,'3星') && !strpos($content,'2星') && !strpos($content,'1星')) {
                                $date = date('Y-m-d',$order['place_time']);
                                $date2 = date('Y.m.d',$order['place_time']);
                                $date3 = date('Y-m-d',($order['place_time']+86400));
                                $date4 = date('Y.m.d',($order['place_time']+86400));
                                $noarr = explode('5星', $content);
                                $logtext .= '，反馈识别：'.count($noarr);
                                if (count($noarr)>=3) {
                                    // 反馈识别还需要确定店铺名称和日期
                                    $shop_name = mb_substr($shop_name, 0,6);
                                    $logtext .= '，反馈识别店铺：'.$shop_name;
                                    if (strpos($content,$shop_name)!==false && (strpos($content,$date) || strpos($content,$date2) || strpos($content,$date3) || strpos($content,$date4) || strpos($content,'刚刚') || strpos($content,'分钟前') || strpos($content,'小时前') || strpos($content,'今天'))) {
                                    // if (strpos($content,$shop_name)) {
                                        $resarr['反馈识别']=1;
                                    }
                                }
                                if (!isset($resarr['反馈识别'])) {
                                    $noarr = explode('满意度超赞包装超赞味道超赞', $content);
                                    $logtext .= '，反馈识别满意度超赞包装超赞味道超赞：'.count($noarr);
                                    if (count($noarr)>=2) {
                                        // 反馈识别还需要确定店铺名称和日期
                                        $shop_name = mb_substr($shop_name, 0,6);
                                        if (strpos($content,$shop_name)!==false && (strpos($content,$date) || strpos($content,$date2) || strpos($content,$date3) || strpos($content,$date4) || strpos($content,'刚刚') || strpos($content,'分钟前') || strpos($content,'小时前') || strpos($content,'今天'))) {
                                        // if (strpos($content,$shop_name)) {
                                            $resarr['反馈识别']=1;
                                        }
                                    }
                                }
                                if (!isset($resarr['反馈识别'])) {
                                    $noarr = explode('超赞', $content);
                                    $logtext .= '，反馈识别超赞：'.count($noarr);
                                    if (count($noarr)>=3) {
                                        // 反馈识别还需要确定店铺名称和日期
                                        $shop_name = mb_substr($shop_name, 0,6);
                                        if (strpos($content,$shop_name)!==false && (strpos($content,$date) || strpos($content,$date2) || strpos($content,$date3) || strpos($content,$date4) || strpos($content,'刚刚') || strpos($content,'分钟前') || strpos($content,'小时前') || strpos($content,'今天'))) {
                                        // if (strpos($content,$shop_name)) {
                                            $resarr['反馈识别']=1;
                                        }
                                    }
                                }
                            }
                        }
                        // 识别实付金额：是否有两个5星
                        if (!isset($resarr['实付金额'])) {
                            $noarr = explode('实付款￥', $content);
                            if (isset($noarr[1]) && $noarr[1]) {
                                preg_match_all('/[0-9]+(?:\.[0-9]+)?/', $noarr[1], $matches);
                                $money = isset($matches[0][0])?$matches[0][0]:0;
                                $logtext .= '，实付金额：'.$money;
                                if (floatval($money) && floatval($money)>=$play['user_pay']) {
                                    $resarr['实付金额']=1;
                                }
                            }
                            if (!isset($resarr['实付金额'])) {
                                $noarr = explode('合计￥', $content);
                                if (isset($noarr[1]) && $noarr[1]) {
                                    preg_match_all('/[0-9]+(?:\.[0-9]+)?/', $noarr[1], $matches);
                                    $money = isset($matches[0][0])?$matches[0][0]:0;
                                    $logtext .= '，实付金额：'.$money;
                                    if (floatval($money) && floatval($money)>=$play['user_pay']) {
                                        $resarr['实付金额']=1;
                                    }
                                }
                            }
                            if (!isset($resarr['实付金额'])) {
                                $noarr = explode('共计￥', $content);
                                if (isset($noarr[1]) && $noarr[1]) {
                                    preg_match_all('/[0-9]+(?:\.[0-9]+)?/', $noarr[1], $matches);
                                    $money = isset($matches[0][0])?$matches[0][0]:0;
                                    $logtext .= '，实付金额：'.$money;
                                    if (floatval($money) && floatval($money)>=$play['user_pay']) {
                                        $resarr['实付金额']=1;
                                    }
                                }
                            }
                            if (!isset($resarr['实付金额'])) {
                                $noarr = explode('实付￥', $content);
                                if (isset($noarr[1]) && $noarr[1]) {
                                    preg_match_all('/[0-9]+(?:\.[0-9]+)?/', $noarr[1], $matches);
                                    $money = isset($matches[0][0])?$matches[0][0]:0;
                                    $logtext .= '，实付金额：'.$money;
                                    if (floatval($money) && floatval($money)>=$play['user_pay']) {
                                        $resarr['实付金额']=1;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        } elseif ($shop_type==3) {// 京东
            foreach ($ims as $key => $value) {
                if ($key==2) break;
                if (isset($data[$value]) && $data[$value]) {
                    // 如果是前端传文字内容，不需要ocr识别的情况
                    if (!$contents || $value=='three_image') {
                        if (strpos($data[$value],'://')===false) {
                            $file = config('upload_domain').$data[$value]; // 指定图片文件的本地路径或远程url
                        } else {
                            $file = $data[$value]; // 指定图片文件的本地路径或远程url
                        }
                        $ocr = new \services\BaiduocrService(); // 创建对象
                        $result = $ocr->ocr($file); // 调用对象开放的函数
                        if (!isset($result['content'])) { // 识别成功
                            return false;
                        }
                        $ocrdata = $result; // 取得数据
                        if (!$ocrdata['content']) return false;
                        $content = str_replace(' ', '', $ocrdata['content']);
                    } else {
                        $content = $contents;
                    }

                    $content = str_replace('（', '', $content);
                    $content = str_replace('(', '', $content);
                    $content = str_replace('）', '', $content);
                    $content = str_replace(')', '', $content);
                    $content = str_replace('：', ':', $content);
                    $content = str_replace('！', '', $content);
                    $content = str_replace('!', '', $content);
                    $content =  str_replace(' ', '', $content);
                    $content =  str_replace('·', '.', $content);
                    $content =  str_replace('•', '.', $content);
                    $content =  str_replace('●', '.', $content);
                    $content =  str_replace('¥', '￥', $content);
                    $content = match_dot($content);
                    if (strpos($content, '.')) {
                        $content = match_dot($content);
                    }
                    \think\Log::write($proof['wm_order_sn'].'ocr识别文字：',$content);
                    if (isset($content) && $content) {
                        // 识别订单状态
                        if (!isset($resarr['订单状态']) && (strpos($content, '完成')!==false)) {
                            $resarr['订单状态'] = 1;
                        }
                        // 识别店铺名称
                        $shop_name =  str_replace('（', '', $play['shop_name']);
                        $shop_name =  str_replace('(', '', $shop_name);
                        $shop_name =  str_replace('）', '', $shop_name);
                        $shop_name =  str_replace(')', '', $shop_name);
                        $shop_name =  str_replace(' ', '', $shop_name);
                        $shop_name =  str_replace('！', '', $shop_name);
                        $shop_name =  str_replace('!', '', $shop_name);
                        // $shop_name =  str_replace('.', '', $shop_name);
                        $shop_name =  str_replace('·', '.', $shop_name);
                        $shop_name =  str_replace('・', '.', $shop_name);
                        $shop_name =  str_replace('•', '.', $shop_name);
                        $shop_name =  str_replace('●', '.', $shop_name);
                        $shop_name =  str_replace('.', '', $shop_name);
                        // $shop_name = mb_substr($shop_name, 0,16);
                        $logtext .= '店铺名称：'.$shop_name;
                        // 店铺名称中包含英文匹配15个，不包含英文匹配15个
                        if (preg_match('/[A-Za-z]/', $shop_name)) {
                            $shop_name2 = mb_substr($shop_name, 0,15);
                            if (!isset($resarr['店铺名称']) && strpos($content, $shop_name2)!==false) {
                                $resarr['店铺名称'] = 1;
                                $img_shop_name = $shop_name2;
                            }
                        } else {
                            if (mb_strlen($shop_name)>16) {
                                $shop_name2 = mb_substr($shop_name, 0,14);
                                if (!isset($resarr['店铺名称']) && strpos($content, $shop_name2)!==false) {
                                    $resarr['店铺名称'] = 1;
                                    $img_shop_name = $shop_name2;
                                }
                            } else {
                                $shop_name2 = mb_substr($shop_name, 0,12);
                                if (!isset($resarr['店铺名称']) && strpos($content, $shop_name2)!==false) {
                                    $resarr['店铺名称'] = 1;
                                    $img_shop_name = $shop_name2;
                                }
                            }
                        }
                        // 识别订单号
                        if (!isset($resarr['订单号'])) {
                            $noarr = explode('订单编号', $content);
                            // 订单号的位数
                            $amount = strlen($proof['wm_order_sn']);
                            if (isset($noarr[1]) && $noarr[1]) {
                                $noarr[1] = substr($noarr[1],0,$amount);// 订单号位数
                                $logtext .= '，订单号码：'.$noarr[1];
                                if ($noarr[1]==$proof['wm_order_sn']) {
                                    $resarr['订单号'] = 1;
                                }
                                $wm_order_sn = $noarr[1];
                            }
                            // 识别订单号
                            if (!isset($resarr['订单号'])) {
                                $noarr = explode('订单编号:', $content);
                                // 订单号的位数
                                $amount = strlen($proof['wm_order_sn']);
                                if (isset($noarr[1]) && $noarr[1]) {
                                    $noarr[1] = substr($noarr[1],0,$amount);// 订单号位数
                                    $logtext .= '，订单号码：'.$noarr[1];
                                    if ($noarr[1]==$proof['wm_order_sn']) {
                                        $resarr['订单号'] = 1;
                                    }
                                    $wm_order_sn = $noarr[1];
                                }
                            }
                        }
                        // 识别下单时间：是否是今天下单
                        if (!isset($resarr['下单时间'])) { 
                            $noarr = explode('下单时间', $content);
                            if (isset($noarr[1]) && $noarr[1]) {
                                $days = substr($noarr[1],0,10);// 日期
                                $time = substr($noarr[1],10,8);// 时间
                                $logtext .= '，下单时间：'.$days.$time;
                                $times = strtotime($days.' '.$time);
                                // if ($time && $time<time() && $time>$order['place_time']) {
                                //     $resarr['下单时间'] = 1;
                                // }
                                // 校对下单时间,所处为同一个小时或小时以后提交的订单通过
                                // $time = strtotime(date('Y-m-d H',$time).':00:00');
                                $place_time = strtotime(date('Y-m-d',$order['place_time']).' 00:00:00');
                                if (time()>=$times && $times>=$place_time) {
                                    $resarr['下单时间'] = 1;
                                }
                            }
                            // 识别下单时间：是否是今天下单
                            if (!isset($resarr['下单时间'])) { 
                                $noarr = explode('下单时间:', $content);
                                if (isset($noarr[1]) && $noarr[1]) {
                                    $days = substr($noarr[1],0,10);// 日期
                                    $time = substr($noarr[1],10,8);// 时间
                                    $logtext .= '，下单时间：'.$days.$time;
                                    $times = strtotime($days.' '.$time);
                                    // if ($time && $time<time() && $time>$order['place_time']) {
                                    //     $resarr['下单时间'] = 1;
                                    // }
                                    // 校对下单时间,所处为同一个小时或小时以后提交的订单通过
                                    // $time = strtotime(date('Y-m-d H',$time).':00:00');
                                    $place_time = strtotime(date('Y-m-d',$order['place_time']).' 00:00:00');
                                    if (time()>=$times && $times>=$place_time) {
                                        $resarr['下单时间'] = 1;
                                    }
                                }
                            }
                        }
                        // 识别实付金额：是否有两个5星
                        if (!isset($resarr['实付金额'])) {
                            $noarr = explode('实付款￥', $content);
                            if (isset($noarr[1]) && $noarr[1]) {
                                preg_match_all('/[0-9]+(?:\.[0-9]+)?/', $noarr[1], $matches);
                                $money = isset($matches[0][0])?$matches[0][0]:0;
                                $logtext .= '，实付金额：'.$money;
                                if (floatval($money) && floatval($money)>=$play['user_pay']) {
                                    $resarr['实付金额']=1;
                                }
                            }
                            if (!isset($resarr['实付金额'])) {
                                $noarr = explode('合计￥', $content);
                                if (isset($noarr[1]) && $noarr[1]) {
                                    preg_match_all('/[0-9]+(?:\.[0-9]+)?/', $noarr[1], $matches);
                                    $money = isset($matches[0][0])?$matches[0][0]:0;
                                    $logtext .= '，实付金额：'.$money;
                                    if (floatval($money) && floatval($money)>=$play['user_pay']) {
                                        $resarr['实付金额']=1;
                                    }
                                }
                            }
                            if (!isset($resarr['实付金额'])) {
                                $noarr = explode('实付金额￥', $content);
                                if (isset($noarr[1]) && $noarr[1]) {
                                    preg_match_all('/[0-9]+(?:\.[0-9]+)?/', $noarr[1], $matches);
                                    $money = isset($matches[0][0])?$matches[0][0]:0;
                                    $logtext .= '，实付金额：'.$money;
                                    if (floatval($money) && floatval($money)>=$play['user_pay']) {
                                        $resarr['实付金额']=1;
                                    }
                                }
                            }
                            if (!isset($resarr['实付金额'])) {
                                $noarr = explode('共计￥', $content);
                                if (isset($noarr[1]) && $noarr[1]) {
                                    preg_match_all('/[0-9]+(?:\.[0-9]+)?/', $noarr[1], $matches);
                                    $money = isset($matches[0][0])?$matches[0][0]:0;
                                    $logtext .= '，实付金额：'.$money;
                                    if (floatval($money) && floatval($money)>=$play['user_pay']) {
                                        $resarr['实付金额']=1;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        \think\Log::write($proof['wm_order_sn'].'ocr识别结果：'.$logtext);
        foreach ($defarr as $k => $v) {
            if (!isset($resarr[$v])) {
                $resarr[$v] = 0;
                $res = 0;
            }
        }
        return ['res'=>$res,'resarr'=>$resarr,'money'=>isset($money)?$money:'','img_shop_name'=>isset($img_shop_name)?$img_shop_name:'','wm_order_sn'=>isset($wm_order_sn)?$wm_order_sn:'','place_time'=>isset($times)?date('Y-m-d H:i:s',$times):''];
    }


    public function checkFeedback1($play, $order, $img)
    {
        $img = config('upload_domain').$img;
        $defarr = ['店铺名称','反馈识别'];
        $resarr = [];
        if ($play['shop_type']==1) {//美团
            $ocr = new \services\BaiduocrService(); // 创建对象
            $result = $ocr->ocr($img); // 调用对象开放的函数
            if (!isset($result['content'])) { // 识别成功
                return false;
            }
            $content = str_replace(' ', '', $result['content']);
            $content = str_replace('（', '', $content);
            $content = str_replace('(', '', $content);
            $content = str_replace('）', '', $content);
            $content = str_replace(')', '', $content);
            $content = str_replace('：', ':', $content);
            $content = str_replace('！', '', $content);
            $content = str_replace('!', '', $content);
            // $content =  str_replace('.', '', $content);
            $content =  str_replace('·', '.', $content);
            $content =  str_replace('•', '.', $content);
            $content =  str_replace('●', '.', $content);
            $content =  str_replace('¥', '￥', $content);
            $content = match_dot($content);
            if (strpos($content, '.')) {
                $content = match_dot($content);
            }
            \think\Log::write($order['wm_order_sn'].'ocr识别反馈：',$content);
            if (isset($content) && $content) {
                // 识别店铺名称
                $shop_name =  str_replace('（', '', $play['shop_name']);
                $shop_name =  str_replace('(', '', $shop_name);
                $shop_name =  str_replace('）', '', $shop_name);
                $shop_name =  str_replace(')', '', $shop_name);
                $shop_name =  str_replace(' ', '', $shop_name);
                $shop_name =  str_replace('！', '', $shop_name);
                $shop_name =  str_replace('!', '', $shop_name);
                // $shop_name =  str_replace('.', '', $shop_name);
                $shop_name =  str_replace('·', '.', $shop_name);
                $shop_name =  str_replace('・', '.', $shop_name);
                $shop_name =  str_replace('•', '.', $shop_name);
                $shop_name =  str_replace('●', '.', $shop_name);
                $shop_name =  str_replace('.', '', $shop_name);
                $shop_name = mb_substr($shop_name, 0,6);
                if (!isset($resarr['店铺名称']) && strpos($content, $shop_name)!==false) {
                    $resarr['店铺名称'] = 1;
                }
                // 识别评价：是否有两个5星
                if (!isset($resarr['反馈识别'])) {
                    if (strpos($content,'5星') && !strpos($content,'4星') && !strpos($content,'3星') && !strpos($content,'2星') && !strpos($content,'1星')) {
                        $date = date('Y-m-d',$order['place_time']);
                        $date2 = date('Y.m.d',$order['place_time']);
                        $date3 = date('Y-m-d',($order['place_time']+86400));
                        $date4 = date('Y.m.d',($order['place_time']+86400));
                        $noarr = explode('5星', $content);
                        if (count($noarr)>=3) {
                            // 反馈识别还需要确定店铺名称和日期
                            $shop_name = mb_substr($shop_name, 0,6);
                            if (strpos($content,$shop_name)!==false && (strpos($content,$date) || strpos($content,$date2) || strpos($content,$date3) || strpos($content,$date4) || strpos($content,'今天') || strpos($content,'刚刚') || strpos($content,'分钟前') || strpos($content,'小时前'))) {
                                $resarr['反馈识别']=1;
                            }
                        }
                        // 识别评价：是否有两个5星
                        if (!isset($resarr['反馈识别'])) {
                            $noarr = explode('非常满意', $content);
                            if (count($noarr)>=2) {
                                // 反馈识别还需要确定店铺名称和日期
                                $shop_name = mb_substr($shop_name, 0,6);
                                if (strpos($content,$shop_name)!==false && (strpos($content,$date) || strpos($content,$date2) || strpos($content,$date3) || strpos($content,$date4) || strpos($content,'今天') || strpos($content,'刚刚') || strpos($content,'分钟前') || strpos($content,'小时前'))) {
                                    $resarr['反馈识别']=1;
                                }
                            }
                        }
                    }
                }
            }
        } else {// 饿了么
            $ocr = new \services\BaiduocrService(); // 创建对象
            $result = $ocr->ocr($img); // 调用对象开放的函数
            if (!isset($result['content'])) { // 识别成功
                return false;
            }
            $content = str_replace(' ', '', $result['content']);
            $content = str_replace('（', '', $content);
            $content = str_replace('(', '', $content);
            $content = str_replace('）', '', $content);
            $content = str_replace(')', '', $content);
            $content = str_replace('：', ':', $content);
            $content = str_replace('！', '', $content);
            $content = str_replace('!', '', $content);
            // $content =  str_replace('.', '', $content);
            $content =  str_replace('·', '.', $content);
            $content =  str_replace('•', '.', $content);
            $content =  str_replace('¥', '￥', $content);
            $content = match_dot($content);
            if (strpos($content, '.')) {
                $content = match_dot($content);
            }
            \think\Log::write($order['wm_order_sn'].'ocr识别反馈：',$content);
            if (isset($content) && $content) {
                // 识别店铺名称
                $shop_name =  str_replace('（', '', $play['shop_name']);
                $shop_name =  str_replace('(', '', $shop_name);
                $shop_name =  str_replace('）', '', $shop_name);
                $shop_name =  str_replace(')', '', $shop_name);
                $shop_name =  str_replace(' ', '', $shop_name);
                $shop_name =  str_replace('！', '', $shop_name);
                $shop_name =  str_replace('!', '', $shop_name);
                // $shop_name =  str_replace('.', '', $shop_name);
                $shop_name =  str_replace('·', '.', $shop_name);
                $shop_name =  str_replace('・', '.', $shop_name);
                $shop_name =  str_replace('•', '.', $shop_name);
                $shop_name =  str_replace('.', '', $shop_name);
                $shop_name = mb_substr($shop_name, 0,6);
                if (!isset($resarr['店铺名称']) && strpos($content, $shop_name)!==false) {
                    $resarr['店铺名称'] = 1;
                }
                // 识别评价：是否有两个5星
                if (!isset($resarr['反馈识别'])) {
                    if (strpos($content,'5星') && !strpos($content,'4星') && !strpos($content,'3星') && !strpos($content,'2星') && !strpos($content,'1星')) {
                        $date = date('Y-m-d',$order['place_time']);
                        $date2 = date('Y.m.d',$order['place_time']);
                        $date3 = date('Y-m-d',($order['place_time']+86400));
                        $date4 = date('Y.m.d',($order['place_time']+86400));
                        $noarr = explode('5星', $content);
                        if (count($noarr)>=3) {
                            // 反馈识别还需要确定店铺名称和日期
                            $shop_name = mb_substr($shop_name, 0,6);
                            if (strpos($content,$shop_name)!==false && (strpos($content,$date) || strpos($content,$date2) || strpos($content,$date3) || strpos($content,$date4) || strpos($content,'刚刚') || strpos($content,'分钟前') || strpos($content,'小时前') || strpos($content,'今天'))) {
                                $resarr['反馈识别']=1;
                            }
                        }
                        if (!isset($resarr['反馈识别'])) {
                            $noarr = explode('满意度超赞包装超赞味道超赞', $content);
                            if (count($noarr)>=2) {
                                // 反馈识别还需要确定店铺名称和日期
                                $shop_name = mb_substr($shop_name, 0,6);
                                if (strpos($content,$shop_name)!==false && (strpos($content,$date) || strpos($content,$date2) || strpos($content,$date3) || strpos($content,$date4) || strpos($content,'刚刚') || strpos($content,'分钟前') || strpos($content,'小时前') || strpos($content,'今天'))) {
                                    $resarr['反馈识别']=1;
                                }
                            }
                        }
                        if (!isset($resarr['反馈识别'])) {
                            $noarr = explode('超赞', $content);
                            if (count($noarr)>=3) {
                                // 反馈识别还需要确定店铺名称和日期
                                $shop_name = mb_substr($shop_name, 0,6);
                                if (strpos($content,$shop_name)!==false && (strpos($content,$date) || strpos($content,$date2) || strpos($content,$date3) || strpos($content,$date4) || strpos($content,'刚刚') || strpos($content,'分钟前') || strpos($content,'小时前') || strpos($content,'今天'))) {
                                    $resarr['反馈识别']=1;
                                }
                            }
                        }
                    }
                }
            }
        }
        $res = 1;
        foreach ($defarr as $k => $v) {
            if (!isset($resarr[$v])) {
                $resarr[$v] = 0;
                $res = 0;
            }
        }
        return ['res'=>$res,'resarr'=>$resarr];
    }
}